package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 通过方法对象获取方法的常见信息
 */
public class ReflectDemo6 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");

        Method method = cls.getMethod("say", String.class,int.class);
        String name =  method.getName();
        System.out.println("方法名:"+name);

        Class returnType = method.getReturnType();
        System.out.println("返回值类型:"+returnType);

        Class[] parameterTypes = method.getParameterTypes();
        for (Class c : parameterTypes) {
            System.out.println("参数类型:"+c);
        }

        int count = method.getParameterCount();
        System.out.println("参数个数:"+count);

        int modifiers = method.getModifiers();
        System.out.println("访问权限:"+modifiers);
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("public");
                break;
            case Modifier.PRIVATE:
                System.out.println("private");
                break;
            case Modifier.PROTECTED:
                System.out.println("protected");
                break;
            case Modifier.STATIC:
                System.out.println("static");
                break;
            case Modifier.FINAL:
                System.out.println("final");
                break;
            default:
                System.out.println("default");
                break;
        }

    }
}
